//
//  YQReweetedStatusView.m
//  WeiboOC
//
//  Created by yang on 15/11/20.
//  Copyright © 2015年 yang. All rights reserved.
//

#import "YQReweetedStatusView.h"
#import "YQStatus.h"
@interface YQReweetedStatusView ()
@property (nonatomic, strong) UILabel *retweetedLabel;
@property (nonatomic, strong) YQStatusPictureView *pictureView;
@property (nonatomic, strong)  MASConstraint *bottomConstraints;
@end
@implementation YQReweetedStatusView
-(void)setRetweetedStatus:(YQStatus *)retweetedStatus{
    _retweetedStatus = retweetedStatus;
    self.retweetedLabel.text = retweetedStatus.text;
    [self.bottomConstraints uninstall];
    if (retweetedStatus.imageURLs.count != 0) {
        self.pictureView.imageURLs = retweetedStatus.imageURLs;
        self.pictureView.hidden = NO;
        [self updateConstraints:^(MASConstraintMaker *make) {
            self.bottomConstraints = make.bottom.equalTo(self.pictureView.bottom).equalTo(StatusCellMargin);
        }];
    }else{
        self.pictureView.hidden = YES;
        [self updateConstraints:^(MASConstraintMaker *make) {
            self.bottomConstraints = make.bottom.equalTo(self.retweetedLabel.bottom).offset(StatusCellMargin);
        }];
    }
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
        [self setupUI];
    }
    return self;
}
- (void)setupUI{
    [self addSubview:self.retweetedLabel];
    [self addSubview:self.pictureView];
    [self.retweetedLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self).offset(StatusCellMargin);
    }];
    [self.pictureView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.retweetedLabel.bottom).offset(StatusCellMargin);
        make.left.equalTo(self.retweetedLabel);
        make.height.with.equalTo(200);
    }];
    [self makeConstraints:^(MASConstraintMaker *make) {
        self.bottomConstraints = make.bottom.equalTo(self.pictureView.bottom).offset(StatusCellMargin);
    }];
}
#pragma mark - 懒加载子控件
- (UILabel *)retweetedLabel{
    if (!_retweetedLabel) {
        
        _retweetedLabel = [[UILabel alloc]initWithTitle:@"涛姐是女神" size:14 color:[UIColor darkGrayColor] margin:StatusCellMargin];
    }
    return _retweetedLabel;
}
-(YQStatusPictureView *)pictureView{
    if (!_pictureView) {
        _pictureView = [[YQStatusPictureView alloc]init];
    }
    return _pictureView;
}
@end
